package com.bdqn.carrental.dao;

import com.bdqn.carrental.pojo.UserEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {
    /**
     * 查询信息
      */
    @Select("SELECT * FROM `users` WHERE USERNAME  LIKE CONCAT('%',#{userName},'%') ")
    @ResultType(UserEntity.class)
    List<UserEntity> findAllByUserName(@Param("userName") String userName);

    /**
     * 按姓名查用户
     * @param username
     * @return
     */
    @Select("SELECT * FROM users where USERNAME=#{username}")
    @ResultType(UserEntity.class)
    UserEntity findAllusername(String username);

    /**
     *新增用户
     */
       @Insert("INSERT INTO users (USERNAME, \n" +
            "\tIDENTITY, \n" +
            "\tFULLNAME, \n" +
            "\tSEX, \n" +
            "\tADDRESS, \n" +
            "\tPHONE, \n" +
            "\tPOSITION, \n" +
            "\tUSERLEVEL, \n" +
            "\tUSERPWD, \n" +
            "\tUSERQQ\n" +
            ",USERDLDATE\t)" +
            "  VALUES(#{username},#{identity},#{fullname}," +
            "#{sex},#{address},#{phone},#{position},#{userlevel}," +
            "#{userpwd},#{userQQ},CURDATE())")
    int inseruser(UserEntity userEntity);

    @Delete("DELETE FROM users WHERE USERNAME=#{username}")
    int deluser(String username);

    @Update("UPDATE users SET IDENTITY=#{identity}," +
            "FULLNAME=#{fullname},SEX=#{sex},ADDRESS=#{address}," +
            "PHONE=#{phone},POSITION=#{position}," +
            "USERLEVEL=#{userlevel},USERPWD=#{userpwd}," +
            "USERQQ=#{userQQ},USERDLDATE=#{userdate}" +
            " where USERNAME=#{username}")
    int upduser(UserEntity userEntity);

}
